package day5;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int size = in.nextInt();
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.nextInt();
            }
            int sum = array[0];
            int max = array[0];
            for (int i = 1; i < size; i++) {
                sum = GetMax(sum + array[i],array[i]);
                if(sum >= max) {
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }
    public static int GetMax(int a, int b){
        return (a) > (b) ? (a) : (b);
    }
}
